﻿using Gufa.IServices;
using Gufa.Services;
using Gufa.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Gufa.WebAPI.Models;
using AutoMapper;
using Gufa.WebAPI.Vo;

namespace Gufa.WebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TechesController : ControllerBase
    {
        private readonly ITechService techService;
        private readonly IMapper mapper;
        public TechesController(ITechService techService, IMapper mapper)
        {
            this.techService = techService;
            this.mapper = mapper;
        }

        [HttpGet("{groupId}")]//1C# 2Web 3DataBase 4Java 0Tools
        public async Task<IActionResult> GetTechesByGroupId(int groupId)
        {
            ApiResult<List<TechVo>> result;
            List<Tech> teches = await techService.LoadEntities(tech => tech.DelFlag == 0 && tech.GroupId == groupId).ToListAsync();

            if (teches.Count > 0)
            {
                result = new ApiResult<List<TechVo>>() { Success = true, Message = "查询成功", Data = mapper.Map<List<TechVo>>(teches) };
            }
            else
            {
                result = new ApiResult<List<TechVo>>() { Success = true, Message = "暂无数据", Data = null };
            }

            return Ok(result);
        }
    }
}
